package datastructure;

/**
 * @author XY
 * @version 1.0
 * @date 2022/2/8 9:13
 * @Description
 */
public class Leet58 {

    public static int lengthOfLastWord1(String s) {
        String[] s1 = s.split(" ");
        return s1[s1.length-1].length();
    }

    public static int lengthOfLastWord(String s) {
        char[] chars = s.toCharArray();
        int leng = 0;
        int leng1 = 0;
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]!=' '){
                leng++;
                leng1 = leng;
            }else{
                leng = 0;
            }
        }
        return leng1;
    }

    public static void main(String[] args) {
        String s = "Hello World";
//        String s = "     ";
        System.out.println(lengthOfLastWord(s));
    }
}
